package com.itboye.eweilisten.util.logincontroller;


import android.app.Activity;
import android.util.Log;

import com.itboye.eweilisten.app.MyApplication;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.sputil.SPUtils;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;

/**
 * 登录相关控制类--状态模式</br></br>
 * <p>
 * 登录成功后调用setLoginState(new LoginedState());</br></br>
 * 退出登录后调用setLoginState(new UnLoginState());</br></br>
 * 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 *
 * @author Mr.w
 */
public class LoginController {

    private static ILoginState loginState = new UnLoginState();
    private static PushAgent mPushAgent;

    public static void setLoginState(ILoginState loginState) {

        LoginController.loginState = loginState;
        if (loginState instanceof UnLoginState) {
            Log.d("LoginLoginLoginLogin", "未登录");
        } else if (loginState instanceof LoginedState) {
            Log.d("bytagbytagbytagbytag", "已登录。。。");
            mPushAgent = MyApplication.getInstance().getmPushAgent();
            // mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
            mPushAgent.onAppStart();
            String uid = (String) SPUtils.get(MyApplication.context, null,
                    Const.ID, "");
            mPushAgent.addExclusiveAlias(uid, Const.UMENG_ALIAS, new UTrack.ICallBack() {

                @Override
                public void onMessage(boolean arg0, String arg1) {
                    // TODO Auto-generated method stub
                    System.out.println(arg0 + "arg222" + arg1);
                }
            });
        }
    }
    /**
     * 个人信息
     */
    public static void PersonnalInfomaton(Activity activity, Object data) {
        loginState.PersonnalInfomaton(activity, data);
    }
    /**
     * 我的账户
     */
    public static void myZhangHu(Activity activity, Object data) {
        loginState.myZhangHu(activity, data);
    }
    /**
     * 账户安全
     */
    public static void anQuan(Activity activity, Object data) {
        loginState.anQuan(activity, data);
    }
}
